Attribute VB_Name = "modCanada"
'---------------------------------------------------------------------------------------
'Host Name: ModCanada
'Author: Alpha King
'Date: 01/27/2006
'Version: 1.0.1
'Description - Contains the following functions
'CountryConv    :converts the customer country code to a CAFE-friendly country code
'Digit          :a function to extract the digits from a string
'ProvinceConv   :a function to convert province codes
'ServiceConv    :a function to convert service codes to FSM friendly service codes
'PhoneTrim      :functions to trim unwanted character
'QuoteTrim      :functions to trim unwanted quotes and ticks
'ZipConv        :a function to convert zip codes
'---------------------------------------------------------------------------------------

Option Explicit


'---------------------------------------------------------------------------------------
'Written by Lahcen Boualam on 7/15/03
'Modified by Alpha King on 03/09/07
'This function converts the customer country code
'to a CAFE-friendly country code.
'
'Codes have been added to this one for Tinnerman Palnut
'---------------------------------------------------------------------------------------
Public Function CountryConv(ByVal strCountry As String) As String

    On Error GoTo EH

    Select Case UCase(Trim(strCountry))
        Case "CANADA", "CA", "CDA", "CDN", ""
            strCountry = "CA"          'CANADA
        Case "USA", "U.S.A.", "UNITED STATES", "US", "ETATS UNIS", UCase("United States of America")
            strCountry = "US"          'UNITED STATES
        Case "ALBANIA", "AL"
            strCountry = "AL"          'ALBANIA
        Case "AMERICAN SAMOA", "AS"
            strCountry = "AS"          'AMERICAN SAMOA
        Case "ANDORRA", "AD"
            strCountry = "AD"          'ANDORRA
        Case "ANGOLA", "AO"
            strCountry = "AO"          'ANGOLA
        Case "ANGUILLA", "AI"
            strCountry = "AI"          'ANGUILLA
        Case "ANTIGUA", "AG"
            strCountry = "AG"          'ANTIGUA
        Case "ARGENTINA", "AR", "ARG"
            strCountry = "AR"          'ARGENTINA
        Case "ARMENIA", "AM"
            strCountry = "AM"          'ARMENIA
        Case "ARUBA", "AW"
            strCountry = "AW"          'ARUBA
        Case "AUSTRIA", "AT", "AUSR"
            strCountry = "AT"          'AUSTRIA
        Case "AUSTRALIA", "AU", "AUSTRALIE", "AUST"
            strCountry = "AU"          'AUSTRALIA
        Case "AZERBAIJAN", "AZ"
            strCountry = "AZ"          'AZERBAIJAN
        Case "BAHAMAS", "BS"
            strCountry = "BS"          'BAHAMAS
        Case "BAHRAIN", "BH"
            strCountry = "BH"          'BAHRAIN
        Case "BANGLADESH", "BD"
            strCountry = "BD"          'BANGLADESH
        Case "BARBADOS", "BB"
            strCountry = "BB"          'BARBADOS
        Case "BELARUS", "BY"
            strCountry = "BY"          'BELARUS
        Case "BELGIUM", "BE", "BELGIQUE", "BELG"
            strCountry = "BE"          'BELGIUM
        Case "BELIZE", "BZ"
            strCountry = "BZ"          'BELIZE
        Case "BENIN", "BJ"
            strCountry = "BJ"          'BENIN
        Case "BERMUDA", "BM"
            strCountry = "BM"          'BERMUDA
        Case "BHUTAN", "BT"
            strCountry = "BT"          'BHUTAN
        Case "BOLIVIA", "BO"
            strCountry = "BO"          'BOLIVIA
        Case "BOSNIA-HERZEGOVINA", "BA"
            strCountry = "BA"          'BOSNIA-HERZEGOVINA
        Case "BOTSWANA", "BW"
            strCountry = "BW"          'BOTSWANA
        Case "BRAZIL", "BR", "BRAZ"
            strCountry = "BR"          'BRAZIL
        Case "BRITISH VIRGIN ISLANDS", "VG"
            strCountry = "VG"          'BRITISH VIRGIN ISLANDS
        Case "BRUNEI", "BN"
            strCountry = "BN"          'BRUNEI
        Case "BULGARIA", "BG"
            strCountry = "BG"          'BULGARIA
        Case "BURKINA FASO", "BF"
            strCountry = "BF"          'BURKINA FASO
        Case "BURUNDI", "BI"
            strCountry = "BI"          'BURUNDI
        Case "CAMBODIA", "KH"
            strCountry = "KH"          'CAMBODIA
        Case "CAMEROON", "CM"
            strCountry = "CM"          'CAMEROON
        Case "CAPE VERDE", "CV"
            strCountry = "CV"          'CAPE VERDE
        Case "CAYMAN ISLANDS", "KY"
            strCountry = "KY"          'CAYMAN ISLANDS
        Case "CHAD", "TD"
            strCountry = "TD"          'CHAD
        Case "CHILE", "CL"
            strCountry = "CL"          'CHILE
        Case "CHINA", "CN", "CHN"
            strCountry = "CN"          'CHINA
        Case "COLOMBIA", "CO", "COL"
            strCountry = "CO"          'COLOMBIA
        Case "CONGO", "CG"
            strCountry = "CG"          'CONGO
        Case "COOK ISLANDS", "CK"
            strCountry = "CK"          'COOK ISLANDS
        Case "COSTA RICA", "CR"
            strCountry = "CR"          'COSTA RICA
        Case "CROATIA", "HR"
            strCountry = "HR"          'CROATIA
        Case "CYPRUS", "CY"
            strCountry = "CY"          'CYPRUS
        Case "CZECH REPUBLIC", "CZ", "CZEC"
            strCountry = "CZ"          'CZECH REPUBLIC
        Case "DENMARK", "DK", "DEN"
            strCountry = "DK"          'DENMARK
        Case "DEMOCRATIC REPUBLIC OF CONGO", "CD"
            strCountry = "CD"          'CONGO
        Case "DJIBOUTI", "DJ"
            strCountry = "DJ"          'DJIBOUTI
        Case "DOMINICA", "DM"
            strCountry = "DM"          'DOMINICA
        Case "DOMINICAN REPUBLIC", "DO"
            strCountry = "DO"          'DOMINICAN REPUBLIC
        Case "ECUADOR", "EC"
            strCountry = "EC"          'ECUADOR
        Case "EGYPT", "EG"
            strCountry = "EG"          'EGYPT
        Case "EL SALVADOR", "SV"
            strCountry = "SV"          'EL SALVADOR
        Case "England", "ANGLETERRE", "ENG", "SCOT"
            strCountry = "GB"          'ENGLAND
        Case "EQUATORIAL GUINEA", "GQ"
            strCountry = "GQ"          'EQUATORIAL GUINEA
        Case "ERITREA", "ER"
            strCountry = "ER"          'ERITREA
        Case "ESTONIA", "EE"
            strCountry = "EE"          'ESTONIA
        Case "ETHIOPIA", "ET"
            strCountry = "ET"          'ETHIOPIA
        Case "FAEROE ISLANDS", "FO"
            strCountry = "FO"          'FAEROE ISLANDS
        Case "FINLAND", "FI", "FIN"
            strCountry = "FI"          'FINLAND
        Case "FIJI", "FJ"
            strCountry = "FJ"          'FIJI
        Case "FRANCE", "FR", "FRA"
            strCountry = "FR"          'FRANCE
        Case "FRENCH GUIANA", "GF"
            strCountry = "GF"          'FRENCH GUIANA
        Case "FRENCH POLYNESIA", "PF"
            strCountry = "PF"          'FRENCH POLYNESIA
        Case "GABON", "GA"
            strCountry = "GA"          'GABON
        Case "GAMBIA", "GM"
            strCountry = "GM"          'GAMBIA
        Case "GEORGIA", "GE"
            strCountry = "GE"          'GEORGIA
        Case "GERMANY", "DE", "ALLEMAGNE", "GER"
            strCountry = "DE"          'GERMANY
        Case "GHANA", "GH"
            strCountry = "GH"          'GHANA
        Case "GIBRALTAR", "GI"
            strCountry = "GI"          'GIBRALTAR
        Case "GREECE", "GR"
            strCountry = "GR"          'GREECE
        Case "GREENLAND", "GL"
            strCountry = "GL"          'GREENLAND
        Case "GRENADA", "GD"
            strCountry = "GD"          'GRENADA
        Case "GUADELOUPE", "GP"
            strCountry = "GP"          'GUADELOUPE
        Case "GUAM", "GU"
            strCountry = "GU"          'GUAM
        Case "GUATEMALA", "GT"
            strCountry = "GT"          'GUATEMALA
        Case "GUINEA", "GN"
            strCountry = "GN"          'GUINEA
        Case "GUYANA", "GY"
            strCountry = "GY"          'GUYANA
        Case "HAITI", "HT"
            strCountry = "HT"          'HAITI
         Case "HONDURAS", "HN"
            strCountry = "HN"          'HONDURAS
        Case "HONG KONG", "HK"
            strCountry = "HK"          'HONG KONG
        Case "HUNGARY", "HU"
            strCountry = "HU"          'HUNGARY
        Case "ICELAND", "IS"
            strCountry = "IS"          'ICELAND
        Case "INDIA", "IN", "IND"
            strCountry = "IN"          'INDIA
        Case "INDONESIA", "ID"
            strCountry = "ID"          'INDONESIA
        Case "IRAN", "IR"
            strCountry = "IR"
        Case "IRAQ", "IQ"
            strCountry = "IQ"
        Case "IRELAND", "IE", "IRLANDE", "IRE"
            strCountry = "IE"          'IRELAND
        Case "ISRAEL", "IL", "ISR"
            strCountry = "IL"          'ISRAEL
        Case "ITALY", "IT", "ITALIE", "ITAL"
            strCountry = "IT"          'ITALY
        Case "IVORY COAST", "CI"
            strCountry = "CI"          'IVORY COAST
        Case "JAMAICA", "JM"
            strCountry = "JM"          'JAMAICA
        Case "JAPAN", "JP", "JAPON", "JPN"
            strCountry = "JP"          'JAPAN
        Case "JORDAN", "JO"
            strCountry = "JO"          'JORDAN
        Case "KAZAKHSTAN", "KAZAKSTAN", "KZ"
            strCountry = "KZ"          'KAZAKHSTAN
        Case "KENYA", "KE"
            strCountry = "KE"          'KENYA
        Case "KUWAIT", "KW"
            strCountry = "KW"          'KUWAIT
        Case "KYRGYZSTAN", "KG"
            strCountry = "KG"          'KYRGYZSTAN
        Case "LAOS", "LA"
            strCountry = "LA"          'LAOS
        Case "LATVIA", "LV"
            strCountry = "LV"          'LATVIA
        Case "LEBANON", "LB"
            strCountry = "LB"          'LEBANON
        Case "LESOTHO", "LS"
            strCountry = "LS"          'LESOTHO
        Case "LIBERIA", "LR"
            strCountry = "LR"          'LIBERIA
        Case "LIECHTENSTEIN", "LI"
            strCountry = "LI"          'LIECHTENSTEIN
        Case "LITHUANIA", "LT"
            strCountry = "LT"          'LITHUANIA
        Case "LUXEMBOURG", "LU"
            strCountry = "LU"          'LUXEMBOURG
        Case "MACAU", "MO"
            strCountry = "MO"          'MACAU
        Case "MACEDONIA", "MK"
            strCountry = "MK"          'MACEDONIA
        Case "MADAGASCAR", "MG"
            strCountry = "MG"          'MADAGASCAR
        Case "MALAWI", "MW"
            strCountry = "MW"          'MALAWI
        Case "MALAYSIA", "MY"
            strCountry = "MY"          'MALAYSIA
        Case "MALDIVES", "MV"
            strCountry = "MV"          'MALDIVES
        Case "MALI", "ML"
            strCountry = "ML"          'MALI
        Case "MALTA", "MT"
            strCountry = "MT"          'MALTA
        Case "MARSHALL ISLANDS", "MH"
            strCountry = "MH"          'MARSHALL ISLANDS
        Case "MARTINIQUE", "MQ"
            strCountry = "MQ"          'MARTINIQUE
        Case "MAURITANIA", "MR"
            strCountry = "MR"          'MAURITANIA
        Case "MAURITIUS", "MU"
            strCountry = "MU"          'MAURITIUS
        Case "MEXICO", "MX", "MEXIQUE", "MEX"
            strCountry = "MX"          'MEXICO
        Case "MICRONESIA", "FM"
            strCountry = "FM"          'MICRONESIA
        Case "MOLDOVA", "MD"
            strCountry = "MD"          'MOLDOVA
        Case "MONACO", "MC"
            strCountry = "MC"          'MONACO
        Case "MONGOLIA", "MN"
            strCountry = "MN"          'MONGOLIA
        Case "MONTSERRAT", "MS"
            strCountry = "MS"          'MONTSERRAT
        Case "MOROCCO", "MA", "MOR"
            strCountry = "MA"          'MOROCCO
        Case "MOZAMBIQUE", "MZ"
            strCountry = "MZ"          'MOZAMBIQUE
        Case "NAMIBIA", "NA"
            strCountry = "NA"          'NAMIBIA
        Case "NEPAL", "NP"
            strCountry = "NP"          'NEPAL
        Case "NETHERLANDS", "NL", "NETH"
            strCountry = "NL"          'NETHERLANDS
        Case "NETHERLANDS ANTILLES", "AN"
            strCountry = "AN"          'NETHERLANDS ANTILLES
        Case "NEW CALEDONIA", "NC"
            strCountry = "NC"          'NEW CALEDONIA
        Case "NEW ZEALAND", "NZ"
            strCountry = "NZ"          'NEW ZEALAND
        Case "NICARAGUA", "NI"
            strCountry = "NI"          'NICARAGUA
        Case "NIGER", "NE"
            strCountry = "NE"          'NIGER
        Case "NIGERIA", "NG"
            strCountry = "NG"          'NIGERIA
        Case "NORWAY", "NO", "NOR"
            strCountry = "NO"          'NORWAY
        Case "OMAN", "OM"
            strCountry = "OM"          'OMAN
        Case "PAKISTAN", "PK"
            strCountry = "PK"          'PAKISTAN
        Case "PALAU", "PW"
            strCountry = "PW"          'PALAU
        Case "PALESTINE", "PS"
            strCountry = "PS"
        Case "PANAMA", "PA"
            strCountry = "PA"          'PANAMA
        Case "PAPUA NEW GUINEA", "PG"
            strCountry = "PG"          'PAPUA NEW GUINEA
        Case "PARAGUAY", "PY"
            strCountry = "PY"          'PARAGUAY
        Case "PERU", "PE"
            strCountry = "PE"          'PERU
        Case "PHILIPPINES", "PH", "PHIL"
            strCountry = "PH"          'PHILIPPINES
        Case "POLAND", "PL", "POL"
            strCountry = "PL"          'POLAND
        Case "PORTUGAL", "PT", "PORT"
            strCountry = "PT"          'PORTUGAL
        Case "PUERTO RICO", "PR", "PUER"
            strCountry = "PR"          'PUERTO RICO
        Case "QATAR", "QA"
            strCountry = "QA"          'QATAR
        Case "REUNION", "RE"
            strCountry = "RE"          'REUNION
        Case "ROMANIA", "RO"
            strCountry = "RO"          'ROMANIA
        Case "RUSSIA", "RU", "USSR"
            strCountry = "RU"          'RUSSIA
        Case "RWANDA", "RW"
            strCountry = "RW"          'RWANDA
        Case "SAIPAN", "MP"
            strCountry = "MP"          'SAIPAN
        Case "SAUDI ARABIA", "SA", "SAUD"
            strCountry = "SA"          'SAUDI ARABIA
        Case "SENEGAL", "SN"
            strCountry = "SN"          'SENEGAL
        Case "SEYCHELLES", "SC"
            strCountry = "SC"          'SEYCHELLES
        Case "SINGAPORE", "SG", "SING"
            strCountry = "SG"          'SINGAPORE
        Case "SLOVAK REPUBLIC", "SK"
            strCountry = "SK"          'SLOVAK REPUBLIC
        Case "SLOVENIA", "SI"
            strCountry = "SI"          'SLOVENIA
        Case "SOUTH AFRICA", "ZA", "SAFR"
            strCountry = "ZA"          'SOUTH AFRICA
        Case "SOUTH KOREA", "KOREA", "KR", "KOR"
            strCountry = "KR"          'SOUTH KOREA
        Case "SPAIN", "ES", "ESPAGNE", "SPA"
            strCountry = "ES"          'SPAIN
        Case "SRI LANKA", "LK"
            strCountry = "LK"
        Case "ST. KITTS AND NEVIS", "ST. KITTS", "ST. CHRISTOPHER", "KN"
            strCountry = "KN"          'ST. KITTS AND NEVIS
        Case "ST. LUCIA", "LC"
            strCountry = "LC"          'ST. LUCIA
        Case "ST. VINCENT", "VC"
            strCountry = "VC"          'ST. VINCENT
        Case "SURINAME", "SR"
            strCountry = "SR"          'SURINAME
        Case "SWAZILAND", "SZ"
            strCountry = "SZ"          'SWAZILAND
        Case "SWEDEN", "SE", "SWDN"
            strCountry = "SE"          'SWEDEN
        Case "SWITZERLAND", "CH", "SUISSE"
            strCountry = "CH"          'SWITZERLAND
        Case "SYRIA", "SYRIAN", "SY"
            strCountry = "SY"          'SYRIA
        Case "TAIWAN", "TW", "TAIW"
            strCountry = "TW"          'TAIWAN
        Case "TANZANIA", "TZ"
            strCountry = "TZ"          'TANZANIA
        Case "THAILAND", "TH", "THAI"
            strCountry = "TH"          'THAILAND
        Case "TOGO", "TG"
            strCountry = "TG"          'TOGO
        Case "TRINIDAD AND TOBAGO", "TT"
            strCountry = "TT"          'TRINIDAD AND TOBAGO
        Case "TUNISIA", "TN"
            strCountry = "TN"          'TUNISIA
        Case "TURKEY", "TR", "TURK"
            strCountry = "TR"          'TURKEY
        Case "TURKMENISTAN", "TM"
            strCountry = "TM"          'TURKMENISTAN
        Case "TURKS AND CAICOS ISLANDS", "TC"
            strCountry = "TC"          'TURKS AND CAICOS ISLANDS
        Case "UGANDA", "UG"
            strCountry = "UG"          'UGANDA
        Case "UKRAINE", "UA"
            strCountry = "UA"          'UKRAINE
        Case "UNITED ARAB EMIRATES", "AE"
            strCountry = "AE"          'UNITED ARAB EMIRATES
        Case "UNITED KINGDOM", "GB", "UK"
            strCountry = "GB"          'UNITED KINGDOM
        Case "URUGUAY", "UY"
            strCountry = "UY"          'URUGUAY
        Case "U S VIRGIN ISLANDS", "VI", "U.S. VIRGIN ISLANDS"
            strCountry = "VI"          'U S VIRGIN ISLANDS
        Case "UZBEKISTAN", "UZ"
            strCountry = "UZ"          'UZBEKISTAN
        Case "VANUATU", "VU"
            strCountry = "VU"          'VANUATU
        Case "VATICAN CITY", "VA"
            strCountry = "VA"          'VATICAN CITY
        Case "VENEZUELA", "VE", "VEN"
            strCountry = "VE"          'VENEZUELA
        Case "VIETNAM", "VN", "VIET"
            strCountry = "VN"          'VIETNAM
        Case "WALLIS & FUTUNA", "WF"
            strCountry = "WF"          'WALLIS & FUTUNA
        Case "YEMEN", "YE"
            strCountry = "YE"          'YEMEN
        Case "YUGOSLAVIA", "YU", "YUGO"
            strCountry = "YU"          'YUGOSLAVIA
        Case "ZAMBIA", "ZM"
            strCountry = "ZM"          'ZAMBIA
        Case "ZIMBABWE", "ZW"
            strCountry = "ZW"          'ZIMBABWE
        Case Else
            strCountry = strCountry
    End Select
    
    ' Take off trailing words until success or nothing left
    Dim i As Long
    Dim strName() As String
    Dim strCountryTest As String
    If Len(strCountry) <> 2 Then
        ' Don't disturb original request, use temporary variable
        strCountryTest = strCountry
        strCountryTest = Replace(strCountryTest, ",", "")
        strCountryTest = Replace(strCountryTest, "(", "")
        strCountryTest = Replace(strCountryTest, ")", "")
        ' Go backwards through country to find space
        For i = 1 To Len(strCountryTest) - 1
            If Mid(strCountryTest, Len(strCountryTest) - i, 1) = " " Then
                ' Remove last word and do country conversion
                strCountryTest = Left(strCountryTest, Len(strCountryTest) - i)
                strCountryTest = CountryConv(strCountryTest)
                Exit For
            End If
        Next i
        If Len(strCountryTest) = 2 Then
            strCountry = strCountryTest
        End If
    End If
    
    CountryConv = strCountry
       
    Exit Function
    
EH:
    
    MsgBox Err.Description, vbSystemModal, "ModCountry.CountryConv"

End Function


'---------------------------------------------------------------------------------------
'Written by Joseph Weir
'Return customs value for documents where country requires non-zero.
'---------------------------------------------------------------------------------------
Public Function CountryCustomsValue(ByVal strCountry As String) As Double

    On Error GoTo EH

    Select Case UCase(Trim(strCountry))
        Case "CA", "JP", "PH", "NZ", "SK", "AU", "PG", "NC", "CN", "AM", "AZ", "BY", "GE", "KG", "MD", "RU", "TM", "UA", "UZ", "CZ", "ID", "KR", "TT", "TW"
            CountryCustomsValue = 1
        Case Else
            CountryCustomsValue = 0
    End Select
       
    Exit Function
    
EH:
    
    MsgBox Err.Description, vbSystemModal, "ModCountry.CountryCustomsValue"

End Function


'---------------------------------------------------------------------------------------
'Host Name: ModDigit
'Author: Keith Thomas
'Date: 07/15/2003
'Version: 3.0.1
'Description:
'Contains a function to extract the digits from a string.
'---------------------------------------------------------------------------------------
Public Function Digit(strData As String) As String
    ' Return only Numbers
    
    ' Author: Keith Thomas
    
    ' set Digit to ""
    ' find length of string
    ' loop through each character position and see if chr is a number
    ' if it is numeric character add to Digit varible
     
     Dim intLen As Integer
     Dim intCounter As Integer
     Dim strTemp As String
     Digit = ""
     intLen = Len(strData)
     
     If intLen = 0 Then Exit Function
            
     Do Until intCounter = intLen
        
        intCounter = intCounter + 1
        strTemp = Mid(strData, intCounter, 1)
        
        Select Case Asc(UCase(strTemp))
    
            Case Is < 48
                ' do nothing
            Case Is > 57
                ' do nothing
            Case Else
                Digit = Digit & strTemp
         End Select
        
      Loop


End Function



'---------------------------------------------------------------------------------------
'Host Name: ProvinceConv
'Author: Alpha S. King
'Date: 10/26/2004
'Version: 1.0.1
'Description:
'Contains a function to convert province codes.
'---------------------------------------------------------------------------------------

Public Function ProvinceConv(ByRef strProvCode As String) As String

    On Error GoTo EH

    Select Case UCase(Trim(strProvCode))
        Case "ALBERTA", "AB", "AL"
            strProvCode = "AB"          'ALBERTA
        Case "BRITISH COLUMBIA", "B.C.", "BC"
            strProvCode = "BC"          'BRITISH COLUMBIA
        Case "MANITOBA", "MB", "MA"
            strProvCode = "MB"          'MANITOBA
        Case "NEW BRUNSWICK", "NB"
            strProvCode = "NB"          'NEW BRUNSWICK
        Case "NEWFOUNDLAND AND LABRADOR", "NF", "NL"
            strProvCode = "NF"          'NEWFOUNDLAND AND LABRADOR
        Case "NOVA SCOTIA", "NS"
            strProvCode = "NS"          'NOVA SCOTIA
        Case "NUNAVUT", "NT", "NWT", "NORTH WEST TERRITORIES"
            strProvCode = "NT"          'NWT/NUNAVUT
        Case "ONTARIO", "ON", "ONT"
            strProvCode = "ON"          'ONTARIO
        Case "PRINCE EDWARD ISLAND", "PEI", "PI", "PE"
            strProvCode = "PE"          'PRINCE EDWARD ISLAND
        Case "QUEBEC", "PQ", "QC", "QU"
            strProvCode = "PQ"          'QUEBEC
        Case "SASKATCHEWAN", "SK", "ST"
            strProvCode = "SK"          'SASKATCHEWAN
        Case "YUKON TERRITORY", "YUKON", "YT"
            strProvCode = "YT"          'YUKON TERRITORY
        Case Else
            strProvCode = strProvCode
    End Select
    
    ProvinceConv = strProvCode
       
    Exit Function
EH:
   MsgBox Err.Description, vbSystemModal, "ModProv.ProvinceConv"
End Function



'---------------------------------------------------------------------------------------
' Procedure : ArrayCount
' DateTime  : 08/22/2006
' Purpose   : Function returns the element count of an array
'---------------------------------------------------------------------------------------
'
Private Function ArrayCount(ByRef vntArray As Variant, Optional ByVal intType As Integer = 0) As Integer
 
    ' Set in-line error handling
 
    On Error Resume Next
 
    ' Set return value
 
    ArrayCount = -1
 
    Select Case intType
        Case 0
            ArrayCount = UBound(vntArray)             'Normal
        Case 1
            ArrayCount = UBound(vntArray) + 1         'Delim
        Case 2
            ArrayCount = UBound(vntArray, 2) + 1      'Fixed
    End Select
 
 
    Err.Clear
 
End Function

'---------------------------------------------------------------------------------------
' Procedure : SplitLine
' DateTime  : 08/22/2006
' Purpose   : Parses out a delimited string and returns values in an array
'---------------------------------------------------------------------------------------
'
Private Function SplitLine(strLine As String, Optional strDelimiter As String = ",") As String()
 
    On Error GoTo SplitLine_Error
 
    Dim a As Long
    Dim B As Long
    Dim strCharacter As String
    Dim blnInQualifier As Boolean
    Dim strHolder() As String
 
    ' Search line by character to determine where the delimiter is
    'and if the delimiter is inside a qualifier, then assign
    'the field to the array
    For a = 1 To Len(strLine)
        strCharacter = Mid(strLine, a, Len(strDelimiter))
        Select Case True
            Case strCharacter = strDelimiter
                If Not blnInQualifier Then
                    B = B + 1
                    a = a + (Len(strDelimiter) - 1)
                    If a = Len(strLine) Then
                        If ArrayCount(strHolder) < B Then
                            ReDim Preserve strHolder(B)
                        End If
                    End If
                Else
                    If ArrayCount(strHolder) < B Then
                        ReDim Preserve strHolder(B)
                    End If
                    strHolder(B) = strHolder(B) & Left(strCharacter, 1)
                End If
            Case Left(strCharacter, 1) = Chr(34)
                If blnInQualifier Then
                    If a = Len(strLine) And Mid(strLine, (a - 1), Len(strDelimiter)) = Chr(34) Then
                        ReDim Preserve strHolder(B)
                    End If
                End If
                blnInQualifier = Not blnInQualifier
            Case Else
                If ArrayCount(strHolder) < B Then
                    ReDim Preserve strHolder(B)
                End If
                strHolder(B) = strHolder(B) & Left(strCharacter, 1)
        End Select
    Next a
 
    SplitLine = strHolder
 
    Exit Function
 
SplitLine_Error:
 
    MsgBox Err.Description & " (SplitLine)", vbSystemModal
 
End Function

'---------------------------------------------------------------------------------------
'Host Name: ModService
'Author: Alpha S. King
'Date: 03/11/2004
'Version: 1.31.00
'Description:
'Contains a function to convert service codes to FSM friendly service codes.
'---------------------------------------------------------------------------------------

Public Function ServiceConv(ByRef strCountry As String, ByRef strServiceCode As String) As String

    On Error GoTo EH
        
    If strCountry = "CA" Then
    
        Select Case strServiceCode
            Case "1", "UPSUSSTAND"
                strServiceCode = "1"        'Priority Overnight
            Case "6"
                strServiceCode = "6"        'First Overnight
            Case "92"
                strServiceCode = "92" ' fsmGround  'Ground Service
        End Select
        
    ElseIf strCountry = "US" Then
    
        Select Case strServiceCode
            Case "1", "UPSUSSTAND"
                strServiceCode = "1"    'International Priority Overnight
            Case "2"
                strServiceCode = "2"    'International Economy
            Case "3"
                strServiceCode = "3"    'International First Overnight
            Case "4"
                strServiceCode = "4"    'International Priority Freight
            Case "92", "Ground"
                strServiceCode = "92" ' fsmGround    'International Ground Service
        End Select
    
    Else
    
        Select Case strServiceCode
            Case "1", "92", "UPSUSSTAND"
                strServiceCode = "1"    'Priority Overnight
            Case "2"
                strServiceCode = "2"    'International Economy
         End Select
        
    End If
    
    ServiceConv = strServiceCode
    
    Exit Function
EH:
   MsgBox Err.Description, vbSystemModal, "ModService.ServiceConv"
End Function





'---------------------------------------------------------------------------------------
'Host Name: PhoneTrim
'Author: Alpha S. King
'Date: 01/07/2005
'Version: 1.0.1
'Description:
'Contains functions to trim unwanted character
'---------------------------------------------------------------------------------------

Public Function PhoneTrim(strPhone) As Variant

    On Error GoTo EH
    
    PhoneTrim = Trim(strPhone)
    PhoneTrim = Replace(PhoneTrim, "(", "")
    PhoneTrim = Replace(PhoneTrim, ")", "")
    PhoneTrim = Replace(PhoneTrim, "-", "")
    PhoneTrim = Replace(PhoneTrim, " ", "")
    PhoneTrim = Replace(PhoneTrim, ".", "")
    Exit Function
    
EH:
    PhoneTrim = Null
    
End Function


'---------------------------------------------------------------------------------------
'Host Name: QuoteTrim
'Author: Alpha S. King
'Date: 01/07/2005
'Version: 1.0.1
'Description:
'Contains functions to trim unwanted quotes and ticks
'---------------------------------------------------------------------------------------

Public Function QuoteTrim(strValue) As Variant
    
    On Error GoTo EH
    QuoteTrim = Trim(strValue)
    QuoteTrim = Replace(QuoteTrim, "/", "")
    QuoteTrim = Replace(QuoteTrim, "\", "")
    QuoteTrim = Replace(QuoteTrim, "^", "")
    QuoteTrim = Replace(QuoteTrim, ";", "")
    QuoteTrim = Replace(QuoteTrim, ":", "")
    QuoteTrim = Replace(QuoteTrim, "#", "")
    QuoteTrim = Replace(QuoteTrim, """", "")
    QuoteTrim = Replace(QuoteTrim, "'", "`")
    QuoteTrim = Replace(QuoteTrim, "''", "")
    Exit Function
    
EH:
    QuoteTrim = Null

End Function


'---------------------------------------------------------------------------------------
'Host Name: ModZip
'Author: Alpha S. King
'Date: 02/13/2004
'Version: 1.31.00
'Description:
'Contains a function to convert zip codes.
'---------------------------------------------------------------------------------------

Public Function ZipConv(ByRef strCountry As String, ByRef strZipCode As String) As String
    
    On Error GoTo EH
    Dim intZipLen As Integer

    If strCountry <> "CA" And strCountry <> "GB" Then
        
        strZipCode = Digit(strZipCode)
        intZipLen = Len(strZipCode)
        
        ' NEW ADDITIONAL COUNTRY POSTAL CODES MARCH 23, 2010 Updated
        '4 DIGIT COUNTRY   BE  LU  PT
        '5 DIGIT COUNTRY   FI GR PR
        '6 DIGIT COUNTRY   CN IN SG
        '8 DIGIT COUNTRY   BR
        
        Select Case strCountry
            Case "AU", "AT", "BE", "BG", "CH", "DK", "LU", "NL", "NO", "PH", "PT", "TW"
                '4 digit Postal Codes
                If intZipLen = 0 Then
                    strZipCode = "1111"
                Else
                    strZipCode = "0000" & strZipCode
                    strZipCode = Right(strZipCode, 4)
                End If
            Case "BR", "FI", "FR", "DE", "GR", "ID", "IT", "MY", "MX", "PR", "SG", "ES", "SE", "TH"
                '5 digit Postal Codes
                If intZipLen = 0 Then
                    strZipCode = "11111"
                Else
                    strZipCode = "00000" & strZipCode
                    strZipCode = Right(strZipCode, 5)
                End If
            Case "CN", "IN", "SG"
                '6 digit Postal Codes
                If intZipLen = 0 Then
                    strZipCode = "111111"
                Else
                    strZipCode = "000000" & strZipCode
                    strZipCode = Right(strZipCode, 6)
                End If
            Case "JP"
                '7 digit Postal Codes
                If intZipLen = 0 Then
                    strZipCode = "1111111"
                Else
                    strZipCode = "0000000" & strZipCode
                    strZipCode = Right(strZipCode, 7)
                End If
            Case "BR"
                '8 digit Postal Codes
                If intZipLen = 0 Then
                    strZipCode = "11111111"
                Else
                    strZipCode = "00000000" & strZipCode
                    strZipCode = Right(strZipCode, 8)
                End If
            Case "US"
                '5 digits
                If intZipLen = 0 Then
                    strZipCode = "11111"
                ElseIf intZipLen <= 5 Then
                    strZipCode = "00000" & strZipCode
                    strZipCode = Right(strZipCode, 5)
                Else
                    strZipCode = "00000" & strZipCode
                    strZipCode = Right(strZipCode, 9)
                End If
            Case Else
                strZipCode = strZipCode
        End Select
    End If
        
    ZipConv = strZipCode
    
    Exit Function
EH:
   MsgBox Err.Description, vbSystemModal, "ModZip.ZipConv"
End Function

